package com.lic.system.service.Impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lic.system.mapper.LicenseMapper;
import com.lic.system.pojo.LicensePram;
import com.lic.system.service.LicenseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author Hewb
 * @ClassName: licenseServiceImpl
 * @Description: TODO
 * @date: 2020/7/11 9:27
 * @since JDK 1.8
 */

@Service
public class LicenseServiceImpl extends ServiceImpl<LicenseMapper, LicensePram> implements LicenseService {
    @Resource
    LicenseMapper licenseMapper;

    @Override
    public void insertLicense(LicensePram license) {
        int insert = licenseMapper.insert(license);
    }

    @Override
    public Page<LicensePram> selectLicense(Page<LicensePram> pramPage, LicensePram licensePram) {
        QueryWrapper<LicensePram> wrapper = new QueryWrapper<>();
        String companyName = licensePram.getCompanyName();
        String startTime = licensePram.getStartTime();
        String endTime = licensePram.getEndTime();
        String productName = licensePram.getProductName();
        wrapper.orderByDesc("create_time");
        if (!StringUtils.isEmpty(companyName)) {
            wrapper.like("company_name", companyName);
        }
        if (!StringUtils.isEmpty(startTime)) {
            wrapper.ge("start_time", startTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.le("end_time", endTime);
        }
        if (!StringUtils.isEmpty(productName)) {
            wrapper.like("product_name", productName);
        }
        Page<LicensePram> licensePramPage = licenseMapper.selectPage(pramPage, wrapper);
        return licensePramPage;
    }
}
